﻿using UnityEditor;
using UnityEngine;

public class CopyObjectPath
{
    [MenuItem("GameObject/Copy Name(Include\"\")", priority = 20)]
    public static void CopySelectionAssetName()
    {
        if (Selection.activeGameObject)
            EditorGUIUtility.systemCopyBuffer = "\""+Selection.activeGameObject.name+"\"";
    }

    [MenuItem("GameObject/Copy Full Path", priority = 20)]
    public static void CopySelectionAssetPath()
    {
        string path = string.Empty;
        //有选择到资源
        if (Selection.activeGameObject != null)
        {
            path = GetPath(Selection.activeGameObject.transform);
        }
        EditorGUIUtility.systemCopyBuffer = path;
    }
    private static string GetPath(Transform t)
    {
        if (!t.parent) return t.name;
        return GetPath(t.parent) + "/" + t.name;
    }
}
